﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Character : MonoBehaviour
{
    public SpriteRenderer spriteRenderer;
    protected Animator animator;
    public Vector2 speedVal = Vector2.zero;
    public bool revertForward=false;
    [HideInInspector]
    public int forward { get { return revertForward? -(spriteRenderer.flipX ? -1 : 1): (spriteRenderer.flipX ? -1 : 1); } }
    public bool isDeath = false;
    public Action onDeath;
    protected Weapon weapon;
    public CharacterInfo characterInfo;
    public void BindCharacterInfo(CharacterInfo characterInfo)
    {
        this.characterInfo = characterInfo;
        weapon.SetAttack(characterInfo.attack);
        animator.SetInteger("Weapon", (int)characterInfo.weaponType);
    }


    public virtual void SpawnBullet()
    {
        GameObjectPool.instance.CreateObject("bullet",Resources.Load<GameObject>("Prefabs/Effect/AttackEffectArcher"), transform.position + new Vector3(0.08f * forward, 0.16f, 0),Quaternion.identity, (a)=> { 
            a.GetComponent<ArcherBullet>().SetBullet(forward,gameObject,characterInfo.attack);
        });
        
    }

    public virtual void Awake()
    {
        animator = GetComponentInChildren<Animator>();
        weapon = GetComponentInChildren<Weapon>();
    }
    public virtual void Dush(float time) { }
    public void AddCoin(int count)
    {
        characterInfo.AcquireCoin(count);
    }
}
